package com.huajian;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.huajian.pojo.Test;
import org.apache.commons.io.IOUtils;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;


public class Main {

    public static void main(String[] args) {
        File f = new File("E:\\a_lxl\\smart_health_tools\\src\\main\\resources\\text.json");
        Test test=new Test();
        test=getParam(f);
        Object o = JSON.toJSON(test);
        System.out.println(o);
    }



    private static Test getParam(File file) {
        InputStreamReader read = null;
        BufferedReader bufferedReader = null;
        Test test = null;
        try {
            read = new InputStreamReader(new FileInputStream(file), "utf-8");
            bufferedReader = new BufferedReader(read);
            StringBuilder sb = new StringBuilder();
            String lineTxt = "";
            while (lineTxt != null) {
                lineTxt = bufferedReader.readLine();
                if (lineTxt == null) {
                    break;
                }
                sb.append(lineTxt.trim());
            }
            String json = sb.toString();
            test = JSON.parseObject(json, Test.class);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            IOUtils.closeQuietly(bufferedReader);
            IOUtils.closeQuietly(read);
        }
        return test;
    }
}
